//
//  CQVideoCell.m
//  Pods
//
//  Created by 陈长青 on 2017/4/5.
//
//

#import "CQVideoCell.h"
#import "CQVBNavigationBar.h"

@implementation CQVideoCell

#pragma mark - 生命周期

+ (Class)layerClass {
    
    // 使用视频播放Layer
    return [AVPlayerLayer class];
}

- (void)dealloc {
    
    NSLog(@"%s",__FUNCTION__);
}

#pragma mark - 私有方法

- (void)setVideoPlayer:(CQVideoPlayer *)videoPlayer {
    [_videoPlayer free];
    _videoPlayer = videoPlayer;
    _videoPlayer.delegate = self;
    _videoPlayer.toolBar = self.toolBar;
    
    // 显示图片
    self.imageView.hidden = NO;
    
    // 禁止缩放, 上下滑动
    if (_videoPlayer) {
        
        self.delegate = nil;
        self.alwaysBounceVertical = NO;
    } else {
        
        self.delegate = self;
        self.alwaysBounceVertical = YES;
    }
}

- (void)setToolBar:(UIView<CQToolBarProtocol> *)toolBar {
    [super setToolBar:toolBar];
    self.videoPlayer.toolBar = toolBar;
}

#pragma mark - CQVideoPlayerDelegate

- (void)videoPlayerPrepareToLoadAsset:(CQVideoPlayer *)videoPlayer {
    
    // 打开loading
}

- (void)videoPlayerProgressToLoadAsset:(CQVideoPlayer *)videoPlayer withProgress:(double)progress {
    
    
}

- (void)videoPlayerPrepareToPlay:(CQVideoPlayer *)videoPlayer {
    
    // 关联视频播放器
    [(AVPlayerLayer *) [self layer] setPlayer:_videoPlayer.player];
}

- (void)videoPlayerSuccessToPlay:(CQVideoPlayer *)videoPlayer {
    
    // 隐藏图片
    self.imageView.hidden = YES;
}

- (void)videoPlayerFailureToPlay:(CQVideoPlayer *)videoPlayer {
    
    NSLog(@"播放错误！！！！！！！");
}

@end
